<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>原型模式</title>
</head>
<body>
<script>
    //因为不是构造函数,所以不用大写
    var someCar={
        drive:function(){},
        name:'马自达3'
    };
    //使用OBject.create创建一个新车x
    var anotherCar=Object.create(someCar);
    anotherCar.name='丰田佳美';
    var vehicle={
        getModel:function(){
            console.log('车辆的模具是：'+this.model);
        }
    };
    var car=Object.create(vehicle,{
        'id':{
            value: '123',
            enumerable:true//默认writeable:false,configurable:false
        },
        'model':{
            value:'福特',
            enumerable:true
        }
    });
    var vehiclePrototype={
        init:function(carModel){
            this.model=carModel;
        },
        getModel:function(){
            console.log('车辆模具是'+this.model);
        }
    };
    var vehicle={
        vehicle:function(model){
            function F(){};
            F.prototype=vehiclePrototype;
            var f=new F();
            f.init(model);
            return f;
        }
    }

    var car= vehicle.vehicle('福特Escort');
    car.getModel();
</script>
</body>
</html>